package com.until;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class JDBCUntils {
    private static String driver;
    private static String url;
    private static String username;
    private static String password;

    static {
        Properties pt=new Properties();
        try {
            pt.load(new FileInputStream("Book/jdbc.properties"));
            driver = pt.getProperty("driver");
            url=pt.getProperty("url");
            username=pt.getProperty("username");
            password=pt.getProperty("password");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    static {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public  static Connection getConnection(){
        try {
           return DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void CloesAll(ResultSet rs, Statement stmt,Connection conn){
        if (rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (stmt!=null){
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
